import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class aa {
    int i = 1;
    Object ob = new Object();

    class ta extends Thread {
        @Override
        public void run() {
            synchronized (ob) {
                for (int j = 0; j < 10; ) {
                    while (i % 2 == 0) {
                        System.out.println(i);
                        i=1;
                        j++;
                        ob.notifyAll();
                    }
                    try {
                        ob.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    class tb extends Thread {
        @Override
        public void run() {
            synchronized (ob) {
                for (int j = 0; j < 10; ) {
                    while (i % 2 == 1) {
                        System.out.println(i);
                        i=0;
                        j++;
                        ob.notifyAll();
                    }
                    try {
                        ob.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        aa a = new aa();
        a.new ta().start();
        a.new tb().start();
    }
}
